var Contest=Contest||{};
fastCSharp.Copy(Contest,{
LoadCount:60,
Load:function()
	{
	var SkinValue=fastCSharp.PageView.SkinValue;
	if(SkinValue.SkinValue.topUser)	SkinValue.topUser.Set(this.FormatRank(SkinValue.SkinValue.topUser));
	if(SkinValue.SkinValue.bottomUser)	SkinValue.bottomUser.Set(this.FormatRank(SkinValue.SkinValue.bottomUser));
	SkinValue.ranks.Set(SkinValue.SkinValue.ranks.ToArray(function(Value){return Contest.FormatRank(Value);}));
	if(SkinValue.SkinValue.currentUser&&SkinValue.SkinValue.judgeTicks.toString().charAt(0)!='-')
		{
		this.Judges=[];
		fastCSharp.Poll.Query.ContestId=SkinValue.SkinValue.contest.Id;
		fastCSharp.Poll.Query.ContestTime=SkinValue.SkinValue.judgeTicks;
		if(!this.IsPoll)
			{
			fastCSharp.Poll.OnMessage.Add(fastCSharp.ThisFunction(this,this.OnPoll));
			this.IsPoll=1;
			}
		}
	else	{
		delete fastCSharp.Poll.Query.ContestId;
		delete fastCSharp.Poll.Query.ContestTime;
		}
	},
FormatRank:function(Value)
	{
	Value.Problems=[];
	for(var Problems=fastCSharp.PageView.SkinValue.SkinValue.problems,Index=0;Index-Problems.length;++Index)
		{
		var Problem=Problems[Index];
		Value.Problems.push({ContestLetter:Problem.ContestLetter,Title:Problem.Problem.Title,Path:Problem.Problem.Path.Contest,IsPoint:Value.PointMap&(1<<Index),IsAccepted:Value.AcceptedMap&(1<<Index)});
		}
	return Value;
	},
OnPoll:function(Value)
	{
	if(Value=Value.ContestJudges)
		{
		if(Value.length)
			{
			fastCSharp.Poll.Query.ContestTime=Value[0].Judge.FinishedTicks;
			for(var Ids={},Index=this.Judges.length;Index;Ids[this.Judges[--Index].Judge.Id]=1);
			for(var Index=Value.length;Index;)
				{
				if(!Ids[Value[--Index].Judge.Id])	this.AppendJudge(Value[Index]);
				}
			}
		else	{
			delete fastCSharp.Poll.Query.ContestId;
			delete fastCSharp.Poll.Query.ContestTime;
			}
		}
	},
AppendJudge:function(Judge)
	{
	if(this.IsShowJudge)
		{
		this.Judges.push(Judge);
		if(this.Judges.length==256)	location.reload();
		}
	else	{
		this.IsShowJudge=1;
		this.ShowJudge(Judge);
		}
	var Rank=Judge.Judge.AfterRank,Page=fastCSharp.PageView.SkinValue.SkinValue.pageInfo;
	if(Rank<=Page.Size*Page.Page&&Rank>Page.Size*(Page.Page-1))
		{
		this.PageUserId=Judge.Judge.Remote.User.Id;
		if(this.IsLoadPage)	this.IsLoadPage=2;
		else	{
			this.IsLoadPage=1;
			setTimeout(fastCSharp.ThisFunction(this,this.LoadPage),0);
			}
		}
	},
LoadPage:function()
	{
	fastCSharp.AjaxGet(fastCSharp.ThisFunction(this,this.OnLoadPage),document.location.pathname,fastCSharp.Query,null,1);
	},
OnLoadPage:function(Value)
	{
	if(--this.IsLoadPage)	this.LoadPage();
	else if(Value.ranks)
		{
		var SkinValue=fastCSharp.PageView.SkinValue;
		SkinValue.contest.UserCount.Set(Value.contest.UserCount);
		SkinValue.contest.JudgeUserCount.Set(Value.contest.JudgeUserCount);
		SkinValue.ranks.Set(Value.ranks.ToArray(function(Value){return Contest.FormatRank(Value);}));
		SkinValue.topUser.Set(Value.topUser?this.FormatRank(Value.topUser):null);
		SkinValue.bottomUser.Set(Value.bottomUser?this.FormatRank(Value.bottomUser):null);
		SkinValue.pageInfo.Set(Value.pageInfo);
		if(this.PageUserId-fastCSharp.PageView.SkinValue.SkinValue.currentUser.Id)
			{
			fastCSharp.$Id('user'+this.PageUserId).Class('Show');
			setTimeout(fastCSharp.ThisFunction(this,this.HidePageUser,[this.PageUserId]),1000);
			}
		}
	if(--this.LoadCount==0)	setTimeout(fastCSharp.ThisFunction(location,location.reload),1000);
	},
HidePageUser:function(UserId)
	{
	fastCSharp.$Id('user'+UserId).Class('Show',1);
	},
ShowJudge:function(Judge)
	{
	fastCSharp.PageView.SkinValue.judge.Set(Judge);
	fastCSharp.$Id('judgePopup').Class('Hide',1);
	setTimeout(fastCSharp.ThisFunction(this,this.HideJudge),5000);
	},
HideJudge:function()
	{
	fastCSharp.$Id('judgePopup').Class('Hide');
	setTimeout(fastCSharp.ThisFunction(this,this.CheckJudge),300);
	},
CheckJudge:function()
	{
	if(this.Judges.length)
		{
		var Judge=this.Judges[0];
		this.Judges=this.Judges.slice(1);
		this.ShowJudge(Judge);
		}
	else	this.IsShowJudge=0;
	}
		});
fastCSharp.OnLoad(Contest.Load,Contest);